<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta charset="utf-8" />
    <title>Geogebra 工具</title>
    
    <script src="https://www.geogebra.org/apps/deployggb.js"></script>

    <style>
        body, html {
            margin: 0;
            padding: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
        
        .main-content-area {
            width: 100%;	
            height: 100vh;
            display: flex;
            flex-direction: column;
        }
        
        .ggb-container {
            flex: 1;
            min-height: 0; /* 修复flex布局中的Chrome bug */
            width: 100%;
            position: relative;
        }
        
        #ggbApplet {
            position: absolute;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
        }
    </style>
</head>

<body>
    <div class="main-content-area">
        <div class="ggb-container">
            <div id="ggbApplet"></div>
        </div>
    </div>
    
    <script>       
        const parameters = {
            "id": "ggbApplet",
            "showMenuBar": true,
            "showAlgebraInput": true,
            "showToolBar": true,
            "showToolBarHelp": true,
            "showResetIcon": true,
            "enableLabelDrags": true,
            "enableShiftDragZoom": true,
            "enableRightClick": true,
            "errorDialogsActive": false,
            "useBrowserForJS": false,
            "allowStyleBar": false,
            "preventFocus": false,
            "showZoomButtons": true,
            "capturingThreshold": 3,
            "showFullscreenButton": true,
            "scale": 1,
            "disableAutoScale": false,
            "allowUpscale": false,
            "clickToLoad": false,
            "appName": "classic",
            "buttonRounding": 0.7,
            "buttonShadows": false,
            "language": "zh-CN",
            "appletOnLoad": function(api) {
                ggbApp = api;
                // 初始调整大小
                resizeApplet();
                // 窗口大小改变时重新调整大小
                window.addEventListener('resize', resizeApplet);
            }
        };

        // 调整GeoGebra应用大小
        function resizeApplet() {
            const container = document.querySelector('.ggb-container');
            const width = container.offsetWidth;
            const height = container.offsetHeight;
            
            // 如果应用已加载，强制重绘
            if (ggbApp && typeof ggbApp.recalculateEnvironments === 'function') {
                ggbApp.setSize(width, height);
            }
        }

        // Initialize GeoGebra Applet
        function initGeoGebra() {
            const applet = new GGBApplet(parameters, true);
            applet.inject('ggbApplet');
            // TODO: 在这里添加你的GeoGebra代码
        }
        
        // Initialize app
        document.addEventListener('DOMContentLoaded', () => {
            initGeoGebra();
        });
        
        // 处理窗口大小变化
        window.addEventListener('resize', resizeApplet);
    </script>
</body>
</html>